package de.baumann.browser.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import de.baumann.browser.R
import de.baumann.browser.api.net.vo.Improve

class ExploreAdapter(var context: Context,
                     var explores: List<Improve>,
                     var itemClickListener: RvItemClickListener
) : RecyclerView.Adapter<ExploreAdapter.ExploreViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExploreViewHolder {
        val itemView = LayoutInflater.from(context).inflate(R.layout.item_explore, parent, false)
        return ExploreViewHolder(itemView)
    }

    override fun getItemCount(): Int {
        return explores.size
    }

    override fun onBindViewHolder(holder: ExploreViewHolder, position: Int) {
        holder.bg.setImageResource(explores[position].bg)
        holder.title.text = explores[position].title
        holder.subTitle.text = explores[position].subTitle
        holder.itemView.setOnClickListener {
            itemClickListener.onClick(position)
        }
    }

    class ExploreViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var bg: ImageView = itemView.findViewById(R.id.ivExploreBg)
        var title: TextView = itemView.findViewById(R.id.tvExploreTitle)
        var subTitle: TextView = itemView.findViewById(R.id.tvExploreSubTitle)
    }
}
